//:C15:AddingVirtuals.cpp
// Adding virtuals in drivation
#include <iostream>
#include <string>
using namespace std;

class Pet
{
    string pname;
    public:
        Pet(const string &petName) : pname(petName){}
        virtual string name() const{ return pname; }
        virtual string speak() const{ return ""; }
};

class Dog : public Pet
{
    string name;
    public:
        Dog(const string &petName) : Pet(petName){}
        // New virutal function in the Dog class：
        virtual string sit() const
        {
            return Pet::name() + " says 'Bark!'";
        }
};

int main(void)
{
    Pet *p[] = {new Pet("generic"), new Dog("bob")};
    cout << "p[0]->speak() = "
         << p[0]->speak() << endl;
    cout << "p[1]->speak() = "
         << p[1]->speak() << endl;         
    // ! cout << "p[1]->sit() = "
    // !      << p[1]->sit() << endl;     
}